const swaggerJSDoc = require('swagger-jsdoc')
const path = require('path')
const rootPath = path.resolve(__dirname, '..') // 获取项目根目录

const options = {
    definition: {
        openapi: '3.0.0',
        info: {
            title: '博客项目 API 文档',
            version: '1.0.0',
            description: '博客项目 API 接口文档',
            contact: {
                name: 'API 支持',
                email: 'support@example.com'
            }
        },

        // https 配置
        schemes: ['http', 'https'],
        host: 'https://www.qxclude.cn',
        basePath: '/',

        // 服务器信息
        servers: [
            {
                url: 'http://localhost:9000',
                description: '开发服务器'
            }, {
                url: 'https://www.qxclude.cn/prod-api',
                description: '生产服务器'
            }
        ],
        components: {
            securitySchemes: {
                BearerAuth: {
                    type: 'http',
                    scheme: 'bearer',
                    bearerFormat: 'JWT'
                }
            }
        }
    },

    // 指定包含注释的路由文件路径
    apis: [
        './src/routes/*.js',
        './src/controllers/*.js'
    ]
}

const swaggerSpec = swaggerJSDoc(options)
// 调试输出
console.log('Swagger 已加载路径:', Object.keys(swaggerSpec.paths || {}).length)
module.exports = swaggerSpec
